<?php
namespace Common\Model;

use Think\Model;

/**
 * 记录日志
 */
class SystemLogModel extends Model
{

    protected function _initialize()
    {
        $this->trueTableName = 'lock_systemlogs';
    }

    function write($params)
    {
        if (!is_array($params)) {
            return false;
        }

        $allowedLevels = array('debug','info','notice','warning','error','critical','alert','emergency');
        if (!in_array($params['level'], $allowedLevels)) {
            $params['level'] = 'debug';
        }

        if (empty($params['type'])) {
            $params['type'] = 'default';
        }

        if (empty($params['createby'])) {
            $params['createby'] = 'system';
        }

        $params['createon'] = date('Y-m-d H:i:s');
        return $this->add($params);
    }
}